package org.wangblue.concrete_aggregate;

import org.wangblue.aggregate.Aggregate;
import org.wangblue.concrete_iterator.ConcreteIterator;
import org.wangblue.iterator.Iterator;

import java.util.ArrayList;

/**
 * @Description: 具体聚集类， 继承了抽象类Aggregate
 * @Author: WangBlue
 * @Create: 2024-09-23 10:02
 * @Version: 1.0
 **/

public class ConcreteAggregate extends Aggregate {
    // 声明一个ArrayList 泛型， 用来存放聚合对象
    private ArrayList<Object> objects = new ArrayList<Object>();

    @Override
    public Iterator createIterator() {
        return new ConcreteIterator(this);
    }

    // 返回聚集总个数
    public int getCount() {
        return objects.size();
    }

    public void add(Object object) {
        objects.add(object);
    }

    // 得到指定索引对象
    public Object getCurrentItem(int index) {
        return objects.get(index);
    }
}
